/*
 * JDockToolBar Copyright (C) 2010 The JDockToolBar Team
 * This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE
 * This is free software, and you are welcome to redistribute it
 * under certain conditions; see LICENSE for details.
 */
package com.googlecode.jdocktoolbar.swing;

import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.border.EmptyBorder;

import com.googlecode.jdocktoolbar.swing.ui.DockButtonUI;

// TODO: Auto-generated Javadoc
/**
 * The Class JDockButton.
 * 
 * @author Marco Biscaro
 */
public class JDockButton extends JButton {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 770991953011013441L;

	private boolean showText;
	private boolean mouseOver;

	/**
	 * Creates a <code>JDockButton</code> with the given icon.
	 * 
	 * @param icon
	 *            the button's icon
	 * @param text
	 *            the text
	 */
	public JDockButton(Icon icon, String text, boolean showText) {
		this.showText = showText;

		setIcon(icon);
		if (showText) {
			setText(text);
			addMouseListener(new MouseOverListener());
		} else {
			setToolTipText(text);
		}
		setOpaque(false);
		setBorder(new EmptyBorder(0, 0, 0, 0));
		setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		setUI(DockButtonUI.createUI(this));
	}

	public JDockButton(Icon icon, String text) {
		this(icon, text, true);
	}

	/**
	 * Constructor Blank for add custom GUI forms.
	 */
	public JDockButton() {
		this(new ImageIcon(), "");
	}

	public boolean isShowText() {
		return showText;
	}
	
	public boolean isMouseOver() {
		return mouseOver;
	}
	
	private class MouseOverListener extends MouseAdapter {

		@Override
		public void mouseEntered(MouseEvent e) {
			mouseOver = true;
		}

		@Override
		public void mouseExited(MouseEvent e) {
			mouseOver = false;
		}

	}

}
